<template>
    <div class="notice-container" id="notice">
        <el-button @click="$router.push({ name: 'index',  params: {label: 'notice'}})">返回</el-button>
        <div class="notice-title">{{notice.title}}</div>
        <div class="notice-date">{{timestampToDate(notice.pubDate)}}</div>
        <div class="notice-content" v-html="notice.content"></div>
    </div>
</template>

<script>
import Watermark from '@/utils/watermark'
import {preventContextmenu} from '@/utils/common'
  export default {
    data () {
      return {
        notice: {
          'title': '',
          'pubDate': '',
          'content': ''
        }
      }
    },
    methods: {
      getNoticeDetail () {
        this.$http.get('/business/notice/' + this.$route.params.id).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.notice = res.data
        }).catch(() => {
        })

      },
      //时间戳转为yyyy-MM-dd HH:mm:ss形式
      timestampToDate: function ( cellValue) {
        if(cellValue){
          var date = new Date(parseInt(cellValue) + 8 * 3600 * 1000)
          return date.toJSON().substr(0, 19).replace('T', ' ')
        }
      }
    },
    mounted: function () {
    let email = sessionStorage.getItem('email')
      Watermark.set('notice', email)
      this.getNoticeDetail()
      // 禁用右键
      preventContextmenu('notice')
    }
  }
</script>
<style>
    .notice-container {
        padding: 30px 60px;
    }

    .notice-title{
        font-size: 20px;
        font-weight: bold;
        text-align: center;
    }

    .notice-date{
        text-align: center;
        margin: 10px 0 20px 0;
    }

    .notice-content{

    }
</style>
